﻿using System;
using System.Data;
using System.Data.SqlClient;
using BLL;
using Utils;
namespace UI.ModEmployee
{
    public partial class ShowAreaList : System.Web.UI.Page
    {
        string account = "";
        string areaID = "0";
        EmployeeBiz employeeBiz = new EmployeeBiz();
        AccountBiz accountBiz=new AccountBiz();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] != null)
            {
                User user = Session["user"] as User;
                account = user.Account;    
                //要根据account获取区域
                DataTable dt = accountBiz.GetOneInfo(account);
                if (dt.Rows.Count > 0)
                {
                    if (!string.IsNullOrWhiteSpace(dt.Rows[0]["AreaID"].ToString()))
                    {
                        areaID = dt.Rows[0]["AreaID"].ToString();
                    }
                }
            }
            else
            {
                JSUtility.Alert(this, "您没有登录!请先登录。");
                return;
            }

            if (!IsPostBack)
            {              
                new DepartmentBiz().InitDropDownList(ddlDeptID, "0");
                BindGv("", "", areaID);
            }
        }
        protected void BindGv(string empCode,  string deptID,  string areaID)
        {
            DataTable dt = employeeBiz.GetListByArea(empCode, deptID, areaID);
            int r = dt.Rows.Count;
            gvList.DataSource = dt;
            gvList.DataBind();
            if (r > 0)
            {
                lbAmount.Text = "总人数：" + r.ToString();
            }
        }
      
        protected void btnEmSearch_Click(object sender, EventArgs e)
        {
            if (!AccountBiz.CheckRight(account, "ShowAreaList.aspx", RightChar.Ser))
            {
                JSUtility.Alert(this, "您没有查询员工的权限！");
                return;
            }
            string empCode = txtSeWord.Text.Trim();           
            string deptID = ddlDeptID.SelectedValue.ToString();
             BindGv(empCode,  deptID,  areaID);
        }

        
    }
}